package com.ktdaddy.controller.system;

import com.ktdaddy.request.UserQueryReq;
import com.ktdaddy.utils.PageResult;
import com.ktdaddy.vo.PermissionNodeVO;
import com.ktdaddy.request.UserReq;
import com.ktdaddy.response.UserInfoResp;
import com.ktdaddy.service.UserService;
import com.ktdaddy.utils.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author kdaddy@163.com
 * @date 2021/4/28 22:34
 * 用户信息相关接口
 */
@Api(value = "用户相关", tags = {"用户相关的api接口"})
@RequestMapping("/whale/system/users")
@RestController
public class UserController {

    @Resource
    private UserService userService;

    @ApiOperation(value = "用户注册", notes = "用户注册", httpMethod = "POST")
    @PostMapping("/register")
    public ApiResponse register(@RequestBody UserReq userReq) {
        Integer kernelId = userService.registerUserInfo(userReq);
        return ApiResponse.ok(kernelId);
    }

    @ApiOperation(value = "新增用户信息", notes = "新增用户信息", httpMethod = "POST")
    @PostMapping("/createUser")
    public ApiResponse createUser(@RequestBody @Valid UserReq userReq) {
        Integer kernelId = userService.createUser(userReq);
        return ApiResponse.ok(kernelId);
    }

    @ApiOperation(value = "更新用户信息", notes = "更新用户信息", httpMethod = "POST")
    @PostMapping("/updateUser")
    public ApiResponse updateUser(@RequestBody @Valid UserReq userReq) {
        Integer kernelId = userService.updateUser(userReq);
        return ApiResponse.ok(kernelId);
    }

    @ApiOperation(value = "获取用户信息",notes = "获取用户信息",httpMethod = "GET")
    @GetMapping("/getUserInfo")
    public ApiResponse getUserInfo(){
        UserInfoResp userInfoResp = userService.getUserInfo();
        return ApiResponse.ok(userInfoResp);
    }

    @ApiOperation(value = "获取用户权限编号集合",notes = "获取用户权限集合",httpMethod = "GET")
    @GetMapping("/getPermCode")
    public ApiResponse getPermCode(){
        List<String> permCodes = userService.getPermCode();
        return ApiResponse.ok(permCodes);
    }

    @ApiOperation(value = "根据当前用户权限获取具体的左侧菜单",notes = "获取用户具体的左侧菜单",httpMethod = "GET")
    @GetMapping("getMenuList")
    public ApiResponse getMenuList(){
        List<PermissionNodeVO> menuList = userService.getMenuList();
        return ApiResponse.ok(menuList);
    }

    @ApiOperation(value = "根据所有左侧菜单",notes = "根据所有左侧菜单",httpMethod = "GET")
    @GetMapping("getAllMenuList")
    public ApiResponse getAllMenuList(){
        List<PermissionNodeVO> menuList = userService.getAllMenuList();
        return ApiResponse.ok(menuList);
    }


    @ApiOperation(value = "查询用户列表",notes = "查询用户列表",httpMethod = "GET")
    @GetMapping("/getUserListByPage")
    public ApiResponse getUserListByPage(UserQueryReq deptQueryReq){
        PageResult pageResult = userService.getUserListByPage(deptQueryReq);
        return ApiResponse.ok(pageResult);
    }

}
